{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2.3.0'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "import json\n",
    "import codecs\n",
    "import numpy as np\n",
    "import tensorflow as tf\n",
    "import yaml\n",
    "import DM_process_v1 as DM_process\n",
    "\n",
    "os.environ[\"CUDA_VISIBLE_DEVICES\"] = '1'\n",
    "gpus = tf.config.experimental.list_physical_devices(device_type='GPU')\n",
    "for gpu in gpus:\n",
    "    tf.config.experimental.set_memory_growth(gpu, True)\n",
    "tf.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "params = {\n",
    "    'batch_size': 16,\n",
    "    'epochs': 300,\n",
    "    'drops' : [0.1],\n",
    "    'heads':16,\n",
    "    'head_size':8,\n",
    "    'out_dim':64\n",
    "         }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('./DM_char.json', mode='r', encoding='utf-8') as f:\n",
    "    dicts = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "path = '../stories/all_stories.yml'\n",
    "with open(path, 'r', encoding='utf-8') as f:\n",
    "    dataset = yaml.load(f.read(),Loader=yaml.Loader)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "action2id = dicts['action2id']\n",
    "intent2id = dicts['intent2id']\n",
    "slots2id = dicts['entities2id']\n",
    "id2action = dicts['id2action']\n",
    "id2intent = dicts['id2intent']\n",
    "id2slots = dicts['id2entities']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "previous_action_len = len(action2id)\n",
    "# print(previous_action_len)\n",
    "slots_len = len(slots2id)\n",
    "# print(slots_len)\n",
    "user_intent_len = len(intent2id)\n",
    "# print(user_intent_len)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "data_set = DM_process.split_data(dataset)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "previous_action, slots, user_intent, action = DM_process.extract_conv_data(data_set,action2id,slots2id,intent2id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Dataset(previous_action_inputs, slots_inputs,user_intent_inputs,pre_action):\n",
    "    dataset = tf.data.Dataset.from_tensor_slices(({\n",
    "    \"previous_action_inputs\" : previous_action_inputs,\n",
    "    \"slots_inputs\" : slots_inputs,\n",
    "    \"user_intent_inputs\" : user_intent_inputs\n",
    "    },\n",
    "    {\n",
    "        \"pre_action\" : pre_action\n",
    "    }))\n",
    "    dataset = dataset.batch(params['batch_size'])\n",
    "    return dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_dataset =  Dataset(previous_action, slots, user_intent, action)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tensorflow.keras.layers import Layer\n",
    "\n",
    "class MultiHeadAttention(Layer):\n",
    "    def __init__(\n",
    "            self,\n",
    "            heads,\n",
    "            head_size,\n",
    "            out_dim=None,\n",
    "            use_bias=True,\n",
    "            #             max_value = 1,\n",
    "            #             min_value = -1\n",
    "            **kwargs\n",
    "    ):\n",
    "        super(MultiHeadAttention, self).__init__(**kwargs)\n",
    "        self.heads = heads\n",
    "        self.head_size = head_size\n",
    "        self.out_dim = out_dim\n",
    "        self.use_bias = use_bias\n",
    "\n",
    "    def build(self, input_shape):\n",
    "        super(MultiHeadAttention, self).build(input_shape)\n",
    "        self.q_dense = tf.keras.layers.Dense(\n",
    "            units=self.head_size * self.heads,\n",
    "            use_bias=self.use_bias,\n",
    "            name='q'\n",
    "\n",
    "        )\n",
    "        self.k_dense = tf.keras.layers.Dense(\n",
    "            units=self.head_size * self.heads,\n",
    "            use_bias=self.use_bias,\n",
    "            name='k'\n",
    "        )\n",
    "        self.v_dense = tf.keras.layers.Dense(\n",
    "            units=self.head_size * self.heads,\n",
    "            use_bias=self.use_bias,\n",
    "            name='v'\n",
    "        )\n",
    "        self.o_dense = tf.keras.layers.Dense(\n",
    "            units=self.out_dim,\n",
    "            use_bias=self.use_bias,\n",
    "            name='o'\n",
    "        )\n",
    "\n",
    "    def call(self, inputs):\n",
    "        q = inputs\n",
    "        k = inputs\n",
    "        v = inputs\n",
    "        # 线性变化\n",
    "        qw = self.q_dense(q)\n",
    "        kw = self.k_dense(k)\n",
    "        vw = self.v_dense(v)\n",
    "        # 形状变换\n",
    "        qw = tf.reshape(qw, (-1, tf.shape(q)[1], self.heads, self.head_size))\n",
    "        kw = tf.reshape(kw, (-1, tf.shape(q)[1], self.heads, self.head_size))\n",
    "        vw = tf.reshape(vw, (-1, tf.shape(q)[1], self.heads, self.head_size))\n",
    "        # attention\n",
    "        qkv_inputs = [qw, kw, vw]\n",
    "        o = self.pay_attention_to(qkv_inputs)\n",
    "        o = tf.reshape(o, (-1, tf.shape(o)[1], self.head_size * self.heads))\n",
    "        o = self.o_dense(o)\n",
    "        return o\n",
    "\n",
    "    def pay_attention_to(self, inputs):\n",
    "        (qw, kw, vw) = inputs[:3]\n",
    "        a = tf.einsum('bjhd,bkhd->bhjk', qw, kw)\n",
    "        a = a / self.head_size ** 0.5\n",
    "        A = tf.nn.softmax(a)\n",
    "        o = tf.einsum('bhjk,bkhd -> bjhd', A, vw)\n",
    "        return o"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tensorflow.keras.layers import concatenate, Dropout,LayerNormalization, Dense, add\n",
    "\n",
    "class Encoder(tf.keras.models.Model):\n",
    "    def __init__(\n",
    "            self,\n",
    "            layer_count,\n",
    "            **kwargs\n",
    "    ):\n",
    "        super(Encoder, self).__init__(**kwargs)\n",
    "        self.layer_count = layer_count\n",
    "\n",
    "    def build(self, input_shape):\n",
    "        self.MultiHeadAttention = MultiHeadAttention(heads=params['heads'], head_size=params['head_size'], out_dim=params['out_dim'])\n",
    "        self.dropout= Dropout(0.1)\n",
    "        self.l1 = LayerNormalization(name='normal')\n",
    "        self.feed1 = Dense(params['out_dim'], activation='relu',name='feed')\n",
    "        self.feed2 = Dense(params['out_dim'],name='feed1')\n",
    "        self.dropout1 = Dropout(0.1)\n",
    "        self.l_1 = LayerNormalization(name='normal1')\n",
    "\n",
    "    def call(self, inputs):\n",
    "        state = inputs\n",
    "        for i in range(self.layer_count):\n",
    "            att = self.MultiHeadAttention(state)\n",
    "            att1 = self.dropout(att)\n",
    "            ad = add([att1, state])\n",
    "            l1 = self.l1(ad)\n",
    "            feed1 = self.feed1(l1)\n",
    "            feed2 = self.feed2(feed1)\n",
    "            dropout_1 = self.dropout1(feed2)\n",
    "            ad1 = add([l1,dropout_1])\n",
    "            l_1 = self.l_1(ad1)\n",
    "            state = l_1\n",
    "        return state"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"functional_1\"\n",
      "__________________________________________________________________________________________________\n",
      "Layer (type)                    Output Shape         Param #     Connected to                     \n",
      "==================================================================================================\n",
      "previous_action_inputs (InputLa [(None, 35)]         0                                            \n",
      "__________________________________________________________________________________________________\n",
      "slots_inputs (InputLayer)       [(None, 13)]         0                                            \n",
      "__________________________________________________________________________________________________\n",
      "user_intent_inputs (InputLayer) [(None, 43)]         0                                            \n",
      "__________________________________________________________________________________________________\n",
      "embedding (Embedding)           (None, 35, 64)       8192        previous_action_inputs[0][0]     \n",
      "__________________________________________________________________________________________________\n",
      "embedding_1 (Embedding)         (None, 13, 64)       8192        slots_inputs[0][0]               \n",
      "__________________________________________________________________________________________________\n",
      "embedding_2 (Embedding)         (None, 43, 64)       8192        user_intent_inputs[0][0]         \n",
      "__________________________________________________________________________________________________\n",
      "concatenate (Concatenate)       (None, 91, 64)       0           embedding[0][0]                  \n",
      "                                                                 embedding_1[0][0]                \n",
      "                                                                 embedding_2[0][0]                \n",
      "__________________________________________________________________________________________________\n",
      "encoder (Encoder)               (None, 91, 64)       41792       concatenate[0][0]                \n",
      "__________________________________________________________________________________________________\n",
      "bidirectional (Bidirectional)   (None, 91, 256)      148992      encoder[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "global_average_pooling1d (Globa (None, 256)          0           bidirectional[0][0]              \n",
      "__________________________________________________________________________________________________\n",
      "pre_action (Dense)              (None, 35)           8995        global_average_pooling1d[0][0]   \n",
      "==================================================================================================\n",
      "Total params: 224,355\n",
      "Trainable params: 224,355\n",
      "Non-trainable params: 0\n",
      "__________________________________________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "tf.keras.backend.clear_session()\n",
    "previous_action_inputs = tf.keras.layers.Input(shape=(previous_action_len,), name = 'previous_action_inputs')\n",
    "slots_inputs = tf.keras.layers.Input(shape = (slots_len,), name = 'slots_inputs')\n",
    "user_intent_inputs = tf.keras.layers.Input(shape = (user_intent_len,), name = 'user_intent_inputs')\n",
    "\n",
    "previous_action_embed = tf.keras.layers.Embedding(128,64)(previous_action_inputs)\n",
    "slots_embed = tf.keras.layers.Embedding(128,64)(slots_inputs)\n",
    "user_intent_embed = tf.keras.layers.Embedding(128,64)(user_intent_inputs)\n",
    "\n",
    "utter_inputs = tf.keras.layers.concatenate([previous_action_embed,slots_embed,user_intent_embed],axis=1)\n",
    "atten = Encoder(layer_count=3)(utter_inputs)\n",
    "bilstm = tf.keras.layers.Bidirectional(tf.keras.layers.GRU(128,return_sequences=True))(atten)\n",
    "x_conv = tf.keras.layers.GlobalAveragePooling1D()(bilstm)\n",
    "pre_action = tf.keras.layers.Dense(previous_action_len, activation='softmax',name = 'pre_action')(x_conv)\n",
    "model = tf.keras.Model([previous_action_inputs,slots_inputs,user_intent_inputs],pre_action)\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "losses = {'pre_action': 'categorical_crossentropy'}\n",
    "metrics = {'pre_action': ['accuracy']}\n",
    "optimizer = tf.keras.optimizers.Nadam()\n",
    "model.compile(optimizer, loss=losses, metrics=metrics)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "file_path = '../DM_model_weight/DM_weight_encoder.h5'\n",
    "# checkpoint = tf.keras.callbacks.ModelCheckpoint(file_path,\n",
    "#                                                         save_weights_only=False, save_best_only=True)\n",
    "learning_rate_reduction = tf.keras.callbacks.ReduceLROnPlateau(patience=50, factor=0.5)\n",
    "callbacks_list = [learning_rate_reduction]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/300\n",
      "14/14 [==============================] - 0s 30ms/step - loss: 3.6764 - accuracy: 0.1754\n",
      "Epoch 2/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.4609 - accuracy: 0.1754\n",
      "Epoch 3/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.3823 - accuracy: 0.1754\n",
      "Epoch 4/300\n",
      "14/14 [==============================] - 0s 20ms/step - loss: 3.3496 - accuracy: 0.1754\n",
      "Epoch 5/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.3215 - accuracy: 0.1754\n",
      "Epoch 6/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.3028 - accuracy: 0.1754\n",
      "Epoch 7/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.2927 - accuracy: 0.1422\n",
      "Epoch 8/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.2791 - accuracy: 0.1374\n",
      "Epoch 9/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.2710 - accuracy: 0.1374\n",
      "Epoch 10/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.2611 - accuracy: 0.1374\n",
      "Epoch 11/300\n",
      "14/14 [==============================] - 0s 23ms/step - loss: 3.2498 - accuracy: 0.1374\n",
      "Epoch 12/300\n",
      "14/14 [==============================] - 0s 24ms/step - loss: 3.2419 - accuracy: 0.1374\n",
      "Epoch 13/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 3.2363 - accuracy: 0.1374\n",
      "Epoch 14/300\n",
      "14/14 [==============================] - 0s 23ms/step - loss: 3.2273 - accuracy: 0.1374\n",
      "Epoch 15/300\n",
      "14/14 [==============================] - 0s 24ms/step - loss: 3.2214 - accuracy: 0.1374\n",
      "Epoch 16/300\n",
      "14/14 [==============================] - 0s 21ms/step - loss: 3.2146 - accuracy: 0.1374\n",
      "Epoch 17/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.2102 - accuracy: 0.1374\n",
      "Epoch 18/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 3.2032 - accuracy: 0.1327\n",
      "Epoch 19/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.1981 - accuracy: 0.1137\n",
      "Epoch 20/300\n",
      "14/14 [==============================] - 0s 20ms/step - loss: 3.1937 - accuracy: 0.1137\n",
      "Epoch 21/300\n",
      "14/14 [==============================] - 0s 20ms/step - loss: 3.1879 - accuracy: 0.1137\n",
      "Epoch 22/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.1844 - accuracy: 0.1137\n",
      "Epoch 23/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.1794 - accuracy: 0.1137\n",
      "Epoch 24/300\n",
      "14/14 [==============================] - 0s 26ms/step - loss: 3.1762 - accuracy: 0.1137\n",
      "Epoch 25/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.1724 - accuracy: 0.1137\n",
      "Epoch 26/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.1681 - accuracy: 0.1137\n",
      "Epoch 27/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.1665 - accuracy: 0.1137\n",
      "Epoch 28/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.1650 - accuracy: 0.1137\n",
      "Epoch 29/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.1600 - accuracy: 0.1137\n",
      "Epoch 30/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.1589 - accuracy: 0.1137\n",
      "Epoch 31/300\n",
      "14/14 [==============================] - 0s 20ms/step - loss: 3.1555 - accuracy: 0.1137\n",
      "Epoch 32/300\n",
      "14/14 [==============================] - 0s 20ms/step - loss: 3.2581 - accuracy: 0.0806\n",
      "Epoch 33/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.1711 - accuracy: 0.1374\n",
      "Epoch 34/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 3.1592 - accuracy: 0.1137\n",
      "Epoch 35/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.1523 - accuracy: 0.1137\n",
      "Epoch 36/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.1504 - accuracy: 0.1137\n",
      "Epoch 37/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.1404 - accuracy: 0.1137\n",
      "Epoch 38/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.1366 - accuracy: 0.1137\n",
      "Epoch 39/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.1342 - accuracy: 0.1137\n",
      "Epoch 40/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.1291 - accuracy: 0.1137\n",
      "Epoch 41/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.1259 - accuracy: 0.1137\n",
      "Epoch 42/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.1235 - accuracy: 0.1137\n",
      "Epoch 43/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.1215 - accuracy: 0.1137\n",
      "Epoch 44/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 3.1185 - accuracy: 0.1137\n",
      "Epoch 45/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 3.1173 - accuracy: 0.1232\n",
      "Epoch 46/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.1137 - accuracy: 0.1706\n",
      "Epoch 47/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.1116 - accuracy: 0.1896\n",
      "Epoch 48/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.1087 - accuracy: 0.1896\n",
      "Epoch 49/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.1061 - accuracy: 0.1896\n",
      "Epoch 50/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.1036 - accuracy: 0.1896\n",
      "Epoch 51/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.1014 - accuracy: 0.1896\n",
      "Epoch 52/300\n",
      "14/14 [==============================] - 0s 21ms/step - loss: 3.1005 - accuracy: 0.1896\n",
      "Epoch 53/300\n",
      "14/14 [==============================] - 0s 21ms/step - loss: 3.0970 - accuracy: 0.1896\n",
      "Epoch 54/300\n",
      "14/14 [==============================] - 0s 20ms/step - loss: 3.0944 - accuracy: 0.1896\n",
      "Epoch 55/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.0913 - accuracy: 0.1896\n",
      "Epoch 56/300\n",
      "14/14 [==============================] - 0s 23ms/step - loss: 3.0947 - accuracy: 0.1896\n",
      "Epoch 57/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.0959 - accuracy: 0.1137\n",
      "Epoch 58/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.0952 - accuracy: 0.1896\n",
      "Epoch 59/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.0847 - accuracy: 0.1137\n",
      "Epoch 60/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 3.1209 - accuracy: 0.1137\n",
      "Epoch 61/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.0978 - accuracy: 0.1848\n",
      "Epoch 62/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.0823 - accuracy: 0.1896\n",
      "Epoch 63/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.0736 - accuracy: 0.1896\n",
      "Epoch 64/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.0688 - accuracy: 0.1896\n",
      "Epoch 65/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.0556 - accuracy: 0.1848\n",
      "Epoch 66/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 3.0429 - accuracy: 0.1611\n",
      "Epoch 67/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 3.0269 - accuracy: 0.1896\n",
      "Epoch 68/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 3.0063 - accuracy: 0.1896\n",
      "Epoch 69/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 2.9827 - accuracy: 0.1896\n",
      "Epoch 70/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 2.9491 - accuracy: 0.1611\n",
      "Epoch 71/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 2.9070 - accuracy: 0.1659\n",
      "Epoch 72/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 2.8958 - accuracy: 0.2180\n",
      "Epoch 73/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 2.8569 - accuracy: 0.2370\n",
      "Epoch 74/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 2.7524 - accuracy: 0.2417\n",
      "Epoch 75/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 2.6732 - accuracy: 0.1896\n",
      "Epoch 76/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 2.6192 - accuracy: 0.2322\n",
      "Epoch 77/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 2.5671 - accuracy: 0.2512\n",
      "Epoch 78/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 2.5148 - accuracy: 0.2559\n",
      "Epoch 79/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 2.4659 - accuracy: 0.2654\n",
      "Epoch 80/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 2.4062 - accuracy: 0.2607\n",
      "Epoch 81/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 2.3406 - accuracy: 0.2749\n",
      "Epoch 82/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 2.2655 - accuracy: 0.2844\n",
      "Epoch 83/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 2.1826 - accuracy: 0.3033\n",
      "Epoch 84/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 2.0917 - accuracy: 0.3175\n",
      "Epoch 85/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 2.0080 - accuracy: 0.3649\n",
      "Epoch 86/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 1.9266 - accuracy: 0.4123\n",
      "Epoch 87/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 1.8525 - accuracy: 0.4313\n",
      "Epoch 88/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 1.7633 - accuracy: 0.4597\n",
      "Epoch 89/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 1.7251 - accuracy: 0.4692\n",
      "Epoch 90/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 1.6595 - accuracy: 0.4882\n",
      "Epoch 91/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 1.6150 - accuracy: 0.4550\n",
      "Epoch 92/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 1.6155 - accuracy: 0.4550\n",
      "Epoch 93/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 1.4943 - accuracy: 0.4692\n",
      "Epoch 94/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 1.4602 - accuracy: 0.5071\n",
      "Epoch 95/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 1.4331 - accuracy: 0.5118\n",
      "Epoch 96/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 1.3776 - accuracy: 0.5118\n",
      "Epoch 97/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 1.3204 - accuracy: 0.5355\n",
      "Epoch 98/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 1.2792 - accuracy: 0.5403\n",
      "Epoch 99/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 1.2864 - accuracy: 0.5355\n",
      "Epoch 100/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 1.2230 - accuracy: 0.5450\n",
      "Epoch 101/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 1.2008 - accuracy: 0.6066\n",
      "Epoch 102/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 1.1551 - accuracy: 0.5687\n",
      "Epoch 103/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 1.1129 - accuracy: 0.5972\n",
      "Epoch 104/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 1.0952 - accuracy: 0.6066\n",
      "Epoch 105/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 1.0509 - accuracy: 0.6303\n",
      "Epoch 106/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 1.0280 - accuracy: 0.6351\n",
      "Epoch 107/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 1.0217 - accuracy: 0.6398\n",
      "Epoch 108/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.9812 - accuracy: 0.6635\n",
      "Epoch 109/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.9483 - accuracy: 0.6777\n",
      "Epoch 110/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.9238 - accuracy: 0.7062\n",
      "Epoch 111/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.9090 - accuracy: 0.6919\n",
      "Epoch 112/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.8762 - accuracy: 0.6967\n",
      "Epoch 113/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.8504 - accuracy: 0.7109\n",
      "Epoch 114/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.8311 - accuracy: 0.7204\n",
      "Epoch 115/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.8068 - accuracy: 0.7299\n",
      "Epoch 116/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.7896 - accuracy: 0.7251\n",
      "Epoch 117/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.7723 - accuracy: 0.7393\n",
      "Epoch 118/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.7587 - accuracy: 0.7441\n",
      "Epoch 119/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.7554 - accuracy: 0.7346\n",
      "Epoch 120/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.7296 - accuracy: 0.7488\n",
      "Epoch 121/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.7436 - accuracy: 0.7204\n",
      "Epoch 122/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.7284 - accuracy: 0.7725\n",
      "Epoch 123/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.8182 - accuracy: 0.7441\n",
      "Epoch 124/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.8149 - accuracy: 0.7156\n",
      "Epoch 125/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.7435 - accuracy: 0.7536\n",
      "Epoch 126/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.6930 - accuracy: 0.7678\n",
      "Epoch 127/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 0.6624 - accuracy: 0.7773\n",
      "Epoch 128/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.6364 - accuracy: 0.7867\n",
      "Epoch 129/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.6257 - accuracy: 0.7867\n",
      "Epoch 130/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 0.6091 - accuracy: 0.8009\n",
      "Epoch 131/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 0.6036 - accuracy: 0.7867\n",
      "Epoch 132/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.5964 - accuracy: 0.7962\n",
      "Epoch 133/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.5977 - accuracy: 0.7962\n",
      "Epoch 134/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.5757 - accuracy: 0.8009\n",
      "Epoch 135/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.5593 - accuracy: 0.8057\n",
      "Epoch 136/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.6194 - accuracy: 0.7962\n",
      "Epoch 137/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.5922 - accuracy: 0.7915\n",
      "Epoch 138/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.5869 - accuracy: 0.7867\n",
      "Epoch 139/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.5967 - accuracy: 0.7630\n",
      "Epoch 140/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.5415 - accuracy: 0.8104\n",
      "Epoch 141/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.5266 - accuracy: 0.8294\n",
      "Epoch 142/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.5107 - accuracy: 0.8199\n",
      "Epoch 143/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.4991 - accuracy: 0.8294\n",
      "Epoch 144/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4850 - accuracy: 0.8389\n",
      "Epoch 145/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4857 - accuracy: 0.8483\n",
      "Epoch 146/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4668 - accuracy: 0.8531\n",
      "Epoch 147/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.5116 - accuracy: 0.8152\n",
      "Epoch 148/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.5430 - accuracy: 0.8057\n",
      "Epoch 149/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.5989 - accuracy: 0.7867\n",
      "Epoch 150/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.5603 - accuracy: 0.8057\n",
      "Epoch 151/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.6606 - accuracy: 0.7299\n",
      "Epoch 152/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.5468 - accuracy: 0.8246\n",
      "Epoch 153/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4846 - accuracy: 0.8389\n",
      "Epoch 154/300\n",
      "14/14 [==============================] - 0s 19ms/step - loss: 0.4601 - accuracy: 0.8483\n",
      "Epoch 155/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4471 - accuracy: 0.8483\n",
      "Epoch 156/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4428 - accuracy: 0.8389\n",
      "Epoch 157/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4405 - accuracy: 0.8436\n",
      "Epoch 158/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.4252 - accuracy: 0.8531\n",
      "Epoch 159/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.4567 - accuracy: 0.8294\n",
      "Epoch 160/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4380 - accuracy: 0.8483\n",
      "Epoch 161/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4825 - accuracy: 0.8057\n",
      "Epoch 162/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.4638 - accuracy: 0.8341\n",
      "Epoch 163/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.4393 - accuracy: 0.8483\n",
      "Epoch 164/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4207 - accuracy: 0.8578\n",
      "Epoch 165/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.4226 - accuracy: 0.8578\n",
      "Epoch 166/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.3971 - accuracy: 0.8720\n",
      "Epoch 167/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3896 - accuracy: 0.8815\n",
      "Epoch 168/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3862 - accuracy: 0.8863\n",
      "Epoch 169/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3621 - accuracy: 0.8863\n",
      "Epoch 170/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4139 - accuracy: 0.8483\n",
      "Epoch 171/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.3703 - accuracy: 0.8815\n",
      "Epoch 172/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3805 - accuracy: 0.8720\n",
      "Epoch 173/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.5914 - accuracy: 0.8294\n",
      "Epoch 174/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.8976 - accuracy: 0.7251\n",
      "Epoch 175/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.5833 - accuracy: 0.8009\n",
      "Epoch 176/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.5099 - accuracy: 0.8152\n",
      "Epoch 177/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.4596 - accuracy: 0.8389\n",
      "Epoch 178/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.4143 - accuracy: 0.8483\n",
      "Epoch 179/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.4210 - accuracy: 0.8578\n",
      "Epoch 180/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.4140 - accuracy: 0.8578\n",
      "Epoch 181/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3828 - accuracy: 0.8815\n",
      "Epoch 182/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3834 - accuracy: 0.8673\n",
      "Epoch 183/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.3486 - accuracy: 0.8863\n",
      "Epoch 184/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3471 - accuracy: 0.8957\n",
      "Epoch 185/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3484 - accuracy: 0.8863\n",
      "Epoch 186/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.3196 - accuracy: 0.9052\n",
      "Epoch 187/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3177 - accuracy: 0.9147\n",
      "Epoch 188/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3356 - accuracy: 0.8957\n",
      "Epoch 189/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3098 - accuracy: 0.9147\n",
      "Epoch 190/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.3672 - accuracy: 0.8768\n",
      "Epoch 191/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.4088 - accuracy: 0.8910\n",
      "Epoch 192/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3060 - accuracy: 0.9194\n",
      "Epoch 193/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2805 - accuracy: 0.9336\n",
      "Epoch 194/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.3014 - accuracy: 0.9147\n",
      "Epoch 195/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2881 - accuracy: 0.9052\n",
      "Epoch 196/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3262 - accuracy: 0.8910\n",
      "Epoch 197/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2753 - accuracy: 0.9242\n",
      "Epoch 198/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2820 - accuracy: 0.9005\n",
      "Epoch 199/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2712 - accuracy: 0.9147\n",
      "Epoch 200/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2533 - accuracy: 0.9336\n",
      "Epoch 201/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.3146 - accuracy: 0.8815\n",
      "Epoch 202/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.4234 - accuracy: 0.8436\n",
      "Epoch 203/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.5554 - accuracy: 0.8199\n",
      "Epoch 204/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.3941 - accuracy: 0.8626\n",
      "Epoch 205/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.3036 - accuracy: 0.9100\n",
      "Epoch 206/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2809 - accuracy: 0.9100\n",
      "Epoch 207/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2613 - accuracy: 0.9242\n",
      "Epoch 208/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3802 - accuracy: 0.8578\n",
      "Epoch 209/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3132 - accuracy: 0.8957\n",
      "Epoch 210/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3273 - accuracy: 0.9005\n",
      "Epoch 211/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2792 - accuracy: 0.9005\n",
      "Epoch 212/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2549 - accuracy: 0.9194\n",
      "Epoch 213/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2475 - accuracy: 0.9194\n",
      "Epoch 214/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2690 - accuracy: 0.8957\n",
      "Epoch 215/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2179 - accuracy: 0.9336\n",
      "Epoch 216/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2124 - accuracy: 0.9384\n",
      "Epoch 217/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2784 - accuracy: 0.9147\n",
      "Epoch 218/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2771 - accuracy: 0.9052\n",
      "Epoch 219/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3081 - accuracy: 0.8815\n",
      "Epoch 220/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3043 - accuracy: 0.8957\n",
      "Epoch 221/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.3259 - accuracy: 0.8910\n",
      "Epoch 222/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3102 - accuracy: 0.8957\n",
      "Epoch 223/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2253 - accuracy: 0.9289\n",
      "Epoch 224/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2319 - accuracy: 0.9242\n",
      "Epoch 225/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3210 - accuracy: 0.8910\n",
      "Epoch 226/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2676 - accuracy: 0.9100\n",
      "Epoch 227/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2433 - accuracy: 0.9242\n",
      "Epoch 228/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.1970 - accuracy: 0.9479\n",
      "Epoch 229/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.1849 - accuracy: 0.9526\n",
      "Epoch 230/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.1798 - accuracy: 0.9573\n",
      "Epoch 231/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2141 - accuracy: 0.9384\n",
      "Epoch 232/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1942 - accuracy: 0.9573\n",
      "Epoch 233/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2706 - accuracy: 0.9194\n",
      "Epoch 234/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3174 - accuracy: 0.8768\n",
      "Epoch 235/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3283 - accuracy: 0.8863\n",
      "Epoch 236/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3441 - accuracy: 0.8910\n",
      "Epoch 237/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2575 - accuracy: 0.9194\n",
      "Epoch 238/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.3043 - accuracy: 0.8815\n",
      "Epoch 239/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2682 - accuracy: 0.8957\n",
      "Epoch 240/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2123 - accuracy: 0.9242\n",
      "Epoch 241/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2013 - accuracy: 0.9479\n",
      "Epoch 242/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.1834 - accuracy: 0.9479\n",
      "Epoch 243/300\n",
      "14/14 [==============================] - 0s 18ms/step - loss: 0.5124 - accuracy: 0.8341\n",
      "Epoch 244/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.3461 - accuracy: 0.8863\n",
      "Epoch 245/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2837 - accuracy: 0.9100\n",
      "Epoch 246/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2356 - accuracy: 0.9479\n",
      "Epoch 247/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2069 - accuracy: 0.9526\n",
      "Epoch 248/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2030 - accuracy: 0.9526\n",
      "Epoch 249/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.1987 - accuracy: 0.9431\n",
      "Epoch 250/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.1959 - accuracy: 0.9479\n",
      "Epoch 251/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1776 - accuracy: 0.9526\n",
      "Epoch 252/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1692 - accuracy: 0.9526\n",
      "Epoch 253/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1645 - accuracy: 0.9573\n",
      "Epoch 254/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1587 - accuracy: 0.9573\n",
      "Epoch 255/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.1541 - accuracy: 0.9573\n",
      "Epoch 256/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1520 - accuracy: 0.9573\n",
      "Epoch 257/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1435 - accuracy: 0.9621\n",
      "Epoch 258/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1509 - accuracy: 0.9573\n",
      "Epoch 259/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1402 - accuracy: 0.9621\n",
      "Epoch 260/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1360 - accuracy: 0.9621\n",
      "Epoch 261/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1520 - accuracy: 0.9621\n",
      "Epoch 262/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1371 - accuracy: 0.9668\n",
      "Epoch 263/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1622 - accuracy: 0.9479\n",
      "Epoch 264/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.1858 - accuracy: 0.9384\n",
      "Epoch 265/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1525 - accuracy: 0.9526\n",
      "Epoch 266/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.1415 - accuracy: 0.9526\n",
      "Epoch 267/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1327 - accuracy: 0.9621\n",
      "Epoch 268/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1223 - accuracy: 0.9716\n",
      "Epoch 269/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1275 - accuracy: 0.9668\n",
      "Epoch 270/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1205 - accuracy: 0.9668\n",
      "Epoch 271/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1158 - accuracy: 0.9716\n",
      "Epoch 272/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1464 - accuracy: 0.9526\n",
      "Epoch 273/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3229 - accuracy: 0.9052\n",
      "Epoch 274/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.3677 - accuracy: 0.8483\n",
      "Epoch 275/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.4532 - accuracy: 0.8246\n",
      "Epoch 276/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.4849 - accuracy: 0.8246\n",
      "Epoch 277/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.3322 - accuracy: 0.8910\n",
      "Epoch 278/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2520 - accuracy: 0.9242\n",
      "Epoch 279/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2275 - accuracy: 0.9431\n",
      "Epoch 280/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2058 - accuracy: 0.9479\n",
      "Epoch 281/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1915 - accuracy: 0.9526\n",
      "Epoch 282/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1708 - accuracy: 0.9526\n",
      "Epoch 283/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1655 - accuracy: 0.9526\n",
      "Epoch 284/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1597 - accuracy: 0.9479\n",
      "Epoch 285/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.1863 - accuracy: 0.9242\n",
      "Epoch 286/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1826 - accuracy: 0.9336\n",
      "Epoch 287/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.1658 - accuracy: 0.9573\n",
      "Epoch 288/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.1625 - accuracy: 0.9336\n",
      "Epoch 289/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1512 - accuracy: 0.9526\n",
      "Epoch 290/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1348 - accuracy: 0.9716\n",
      "Epoch 291/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1262 - accuracy: 0.9763\n",
      "Epoch 292/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1826 - accuracy: 0.9573\n",
      "Epoch 293/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2329 - accuracy: 0.9384\n",
      "Epoch 294/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2146 - accuracy: 0.9242\n",
      "Epoch 295/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1602 - accuracy: 0.9479\n",
      "Epoch 296/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2273 - accuracy: 0.9194\n",
      "Epoch 297/300\n",
      "14/14 [==============================] - 0s 17ms/step - loss: 0.2744 - accuracy: 0.9194\n",
      "Epoch 298/300\n",
      "14/14 [==============================] - 0s 15ms/step - loss: 0.1972 - accuracy: 0.9526\n",
      "Epoch 299/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.1851 - accuracy: 0.9431\n",
      "Epoch 300/300\n",
      "14/14 [==============================] - 0s 16ms/step - loss: 0.2102 - accuracy: 0.9384\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<tensorflow.python.keras.callbacks.History at 0x7fb63b99d110>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.fit(train_dataset,epochs=params['epochs'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "4# model.save_weights('../DM_model_weight/DM_weight_629.h5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.save(file_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
